package com.gmzg.gmzgnews.topic.view;


import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.gmzg.gmzgnews.R;
import com.gmzg.gmzgnews.topic.adapters.CommonFragmentAdapter;
import java.util.ArrayList;

/**
 * main entrance, just like mainActivity
 */
public class TopicFragment extends Fragment  {

    private ViewPager mTopicPager;
    private TabLayout mTopicTabLayout;
    public TopicFragment() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_second, container, false);

        mTopicPager = (ViewPager) view.findViewById(R.id.topic_fragment_pager);
        mTopicTabLayout = ((TabLayout) view.findViewById(R.id.topic_fragment_tab));
        if (mTopicPager != null) {
            ArrayList<BaseFragment> fragments = new ArrayList<>();
            fragments.add(new TopicQuestionFragment());
            fragments.add(new TopicFollowFragment());
            CommonFragmentAdapter fragmentAdapter = new CommonFragmentAdapter(
                    getChildFragmentManager(),
                    fragments);
            mTopicPager.setAdapter(fragmentAdapter);
            mTopicPager.setOffscreenPageLimit(2);
            mTopicTabLayout.setupWithViewPager(mTopicPager);
        }

        return view;
    }


}
